package selenium;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

public class test9 {
//百度视频手机版自动翻页
	public static void main(String[] args1) {
		try {
			//指定设备的分辨率及像素比
			Map<String, Object> deviceMetrics = new HashMap<String, Object>();
			deviceMetrics.put("width", 360);
			deviceMetrics.put("height", 640);
			deviceMetrics.put("pixelRatio", 1);

			Map<String, Object> mobileEmulation = new HashMap<String, Object>();
			mobileEmulation.put("deviceMetrics", deviceMetrics);

			//指定设备的userAgent(此处是一个微信内置浏览器)
			mobileEmulation.put("userAgent", "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Mobile/14G60 MicroMessenger/6.5.12 NetType/WIFI Language/zh_CN");

			//指定其它启动参数(支持所有Chromium启动参数)
			List<String> args = new ArrayList<String>(); //args
			args.add("window-size=375,685"); //设置浏览器窗口大小
			args.add("disable-infobars");  //取消"Chrome正收到自动测试软件的控制"提示
			//args.add("app=http://m.ixigua.com/video/app/user/home/?to_user_id=5854705252&format=html"); //以app模式打开网页(不显示地址栏, 工具栏等. 需要填上对应的地址)
			args.add("https://sv.baidu.com/#doubiju");
			Map<String, Object> chromeOptions = new HashMap<String, Object>();
			chromeOptions.put("mobileEmulation", mobileEmulation);
			chromeOptions.put("args", args);
			DesiredCapabilities capabilities = DesiredCapabilities.chrome();
			capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
			WebDriver driver = new ChromeDriver(capabilities);
			System.out.println("aaa");
			for (int i = 0; i < 9999; i++) {
				//方法一： 
				  //1、操作垂直滚动条，向下移动500像素
				   String setscroll = "document.documentElement.scrollTop=" + "9999999999999999";  //window.history.go(0);
				   //2、水平滚动条，向右移动500像素
				   //String setscroll = "document.documentElement.scrollLeft=" + "500";  
				   
				   JavascriptExecutor jse=(JavascriptExecutor) driver;  
				   jse.executeScript(setscroll); 
			}
			   

		} catch (Exception e) {
			e.printStackTrace();
		}
		 /*driver.quit();*/
	}

}
